# Maintainer: Patrycja Rosa <alpine@ptrcnull.me>
pkgname=libclc
# follow llvm versioning
pkgver=17.0.6
pkgrel=0
_llvmver=${pkgver%%.*}
pkgdesc="Open source implementation of the library requirements of the OpenCL C programming language"
url="https://libclc.llvm.org/"
arch="all"
license="Apache-2.0 WITH LLVM-exception"
depends_dev="$pkgname=$pkgver-r$pkgrel"
makedepends="
	clang$_llvmver
	cmake
	llvm$_llvmver-dev
	llvm$_llvmver-static
	llvm$_llvmver-gtest
	samurai
	spirv-llvm-translator-dev
	"
checkdepends="llvm-test-utils"
subpackages="$pkgname-dev"
source="https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/libclc-$pkgver.src.tar.xz
	https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/cmake-$pkgver.src.tar.xz
	"
builddir="$srcdir/libclc-$pkgver.src"
options="!check" # todo: they fail for some reason

build() {
	CC=clang-$_llvmver \
	CXX=clang++-$_llvmver \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DLLVM_CONFIG="llvm-config-$_llvmver" \
		-DLLVM_SPIRV=/usr/bin/llvm-spirv \
		-DCMAKE_MODULE_PATH="$srcdir/cmake-$pkgver.src/Modules"
	cmake --build build
}

check() {
	cmake --build build --target test
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
6165bfa0112fb42756cd0e83a0d3d4406985b1d6db6eed8abb3bee9a74fcc451cc88928b24231493694035c35d9bcd367aa6a4a67da631cb4ee5e7a98037fee3  libclc-17.0.6.src.tar.xz
b2c5e404ca36542d44e1a7f2801bbcecbcf5f1e8c63b793bb2308228483406bdfe002720aadb913c0228cd2bbe5998465eaadc4a49fad6a5eb6ff907fa5fd45a  cmake-17.0.6.src.tar.xz
"
